package com.mind.ridge.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mind.ridge.pojo.backend.Category;
import com.mind.ridge.service.backend.CategoryService;
import com.mind.ridge.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Mind
 * 菜品分类Controller
 */
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/page")
    public R<IPage> page(Integer page, Integer pageSize) {
        return categoryService.page(page, pageSize);
    }


    @DeleteMapping
    public R<String> delById(Long ids, HttpServletRequest request) {
        return categoryService.delById(ids, request);
    }

    @PostMapping
    public R<String> addCategory(@RequestBody Category category) {
        return categoryService.addCategory(category);
    }

    @PutMapping
    public R<String> updateCategory(@RequestBody Category category) {
        return categoryService.updateCategory(category);
    }

    @GetMapping("/list")
    public R list(Category category) {
        return categoryService.listType(category);
    }
}
